DROP CAST IF EXISTS (INT1 AS INTERVAL);
DROP CAST IF EXISTS (INT2 AS INTERVAL);
DROP CAST IF EXISTS (INT4 AS INTERVAL);
DROP CAST IF EXISTS (FLOAT8 AS INTERVAL);
DROP CAST IF EXISTS (NUMERIC AS INTERVAL);
DROP CAST IF EXISTS (TEXT AS INTERVAL);
DROP CAST IF EXISTS (BPCHAR AS INTERVAL);
DROP CAST IF EXISTS (VARCHAR2 AS INTERVAL);

DROP FUNCTION IF EXISTS pg_catalog.num_to_interval(int1, int4) CASCADE;
DROP FUNCTION IF EXISTS pg_catalog.num_to_interval(int2, int4) CASCADE;
DROP FUNCTION IF EXISTS pg_catalog.num_to_interval(int4, int4) CASCADE;
DROP FUNCTION IF EXISTS pg_catalog.float8_to_interval(float8, int4) CASCADE;
DROP FUNCTION IF EXISTS pg_catalog.num_to_interval(numeric, int4) CASCADE;
DROP FUNCTION IF EXISTS pg_catalog.text_interval(text, int4) CASCADE;

DROP FUNCTION IF EXISTS pg_catalog.TO_INTERVAL(BPCHAR, int);
CREATE OR REPLACE FUNCTION pg_catalog.TO_INTERVAL(BPCHAR)
RETURNS INTERVAL
AS $$  select pg_catalog.interval_in(pg_catalog.bpcharout($1), 0::Oid, -1) $$
LANGUAGE SQL IMMUTABLE STRICT NOT FENCED;

DROP FUNCTION IF EXISTS pg_catalog.TO_INTERVAL(VARCHAR2, int);
CREATE OR REPLACE FUNCTION pg_catalog.TO_INTERVAL(VARCHAR2)
RETURNS INTERVAL
AS $$  select pg_catalog.interval_in(pg_catalog.varcharout($1), 0::Oid, -1) $$
LANGUAGE SQL IMMUTABLE STRICT NOT FENCED;

CREATE CAST (INT1 AS INTERVAL) WITH FUNCTION pg_catalog.numtoday(INT1) AS IMPLICIT;
CREATE CAST (INT2 AS INTERVAL) WITH FUNCTION pg_catalog.numtoday(INT2) AS IMPLICIT;
CREATE CAST (INT4 AS INTERVAL) WITH FUNCTION pg_catalog.numtoday(INT4) AS IMPLICIT;
CREATE CAST (FLOAT8 AS INTERVAL) WITH FUNCTION pg_catalog.float8_interval(FLOAT8) AS IMPLICIT;
CREATE CAST (NUMERIC AS INTERVAL) WITH FUNCTION pg_catalog.numtoday(NUMERIC) AS IMPLICIT;
CREATE CAST (BPCHAR AS INTERVAL) WITH FUNCTION pg_catalog.TO_INTERVAL(BPCHAR) AS IMPLICIT;
CREATE CAST (VARCHAR2 AS INTERVAL) WITH FUNCTION pg_catalog.TO_INTERVAL(VARCHAR2) AS IMPLICIT;
